package com.stable.utils;

import com.stable.config.SpringConfig;
import com.zjiecode.wxpusher.client.WxPusher;
import com.zjiecode.wxpusher.client.bean.Message;
import lombok.extern.log4j.Log4j2;

import java.util.HashSet;
import java.util.Set;

@Log4j2
public class WxPushUtil {

    private static String appToken = "AT_321uywGGIEdJcoe6FRJaA0Sp5xRmGInU";
    private static String myUid = "UID_fMHbgaDsKouFAFB1D0hVHlgZ5YKn";
//	static {
//		SpringConfig efc = SpringUtil.getBean(SpringConfig.class);
//		appToken = efc.getAppToken();
//		myUid = efc.getMyUid();
//	}

    public final static void pushSystem1(String content) {
        WxPushUtil.pushMsg(content, true, null);
    }

    private final static void pushMsg(String content, boolean isMyId, Set<String> uids) {
        try {
            Message message = new Message();
            message.setAppToken(appToken);
            message.setContentType(Message.CONTENT_TYPE_TEXT);
            message.setContent(content + " 时间:" + DateUtil.getTodayYYYYMMDDHHMMSS());
            if (isMyId) {
                message.setUid(myUid);
            } else {
                message.setUids(uids);
            }
            message.setUrl(null);
            log.info("微信推送内容:{},状态:{}", content, WxPusher.send(message).getData().get(0).getStatus());
        } catch (Exception e) {
            ErrorLogFileUitl.writeError(e, "微信推送内容异常", content, "");
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        Set<String> uids = new HashSet<String>();
        uids.add("UID_fMHbgaDsKouFAFB1D0hVHlgZ5YKn");
        Message message = new Message();
        message.setAppToken("AT_321uywGGIEdJcoe6FRJaA0Sp5xRmGInU");
        message.setContentType(Message.CONTENT_TYPE_TEXT);
        message.setContent("不加限制的消息");
        message.setUids(uids);
        message.setUrl(null);
        System.out.println(WxPusher.send(message).getData().get(0).getStatus());
    }
}
